package com.victor.modular.system.controller;

import com.victor.common.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import com.victor.core.util.DateUtil;
import java.util.*;
/**
 * 测试管理控制器
 *
 * @author victor
 * @Date 2018-07-02 10:35:43
 */
@Controller
@RequestMapping("/testManager")
public class TestManagerController extends BaseController {

    private String PREFIX = "/system/testManager/";

    /**
     * 跳转到测试管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "testManager.html";
    }

    /**
     * 跳转到添加测试管理
     */
    @RequestMapping("/testManager_add")
    public String testManagerAdd() {
        return PREFIX + "testManager_add.html";
    }

    /**
     * 跳转到修改测试管理
     */
    @RequestMapping("/testManager_update/{testManagerId}")
    public String testManagerUpdate(@PathVariable Integer testManagerId, Model model) {
        Map<String,Object> map  =new HashMap<>();
        map.put("id",testManagerId);
        map.put("name","测试数据"+testManagerId);
        map.put("sex",testManagerId%2==0?1:2);
        model.addAttribute("testManager",map);
        model.addAttribute("testManager",map);
        return PREFIX + "testManager_edit.html";
    }

    /**
     * 获取测试管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam(required = false) String name,@RequestParam(required = false) Integer sex,
       @RequestParam(required = false) String beginTime,@RequestParam(required = false) String endTime) {
        logger.info("姓名：{}，性别：{}，开始时间：{}，结束时间：{}，",name,sex,beginTime,endTime);
        List<Map<String,Object>> list= new ArrayList<>();
        for(int i =0;i<99;i++){
            Map<String,Object> map  =new HashMap<>();
            map.put("id",i);
            map.put("name","测试数据"+i);
            map.put("sex",i%2==0?1:2);
            map.put("sexName",i%2==0?"男":"女");
            map.put("createtime", DateUtil.format(new Date()));
            list.add(map);
        }
        return list;
    }

    /**
     * 新增测试管理
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add() {
        return super.SUCCESS_TIP;
    }

    /**
     * 删除测试管理
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam(required = true) Integer[] ids) {
        logger.info("删除的数据id：{}",Arrays.toString(ids));
        return SUCCESS_TIP;
     }


    /**
     * 修改测试管理
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update() {
        return super.SUCCESS_TIP;
    }

    /**
     * 测试管理详情
     */
    @RequestMapping(value = "/detail")
    @ResponseBody
    public Object detail() {
        return null;
    }
}
